
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>对象管理 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="enum.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">Java</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="object-mgmr.html">
            
                <a href="object-mgmr.html">
            
                    
                    对象管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="enum.html">
            
                <a href="enum.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="object-common.html">
            
                <a href="object-common.html">
            
                    
                    对象通用行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="concurrent.html">
            
                <a href="concurrent.html">
            
                    
                    线程和并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="concurrent/how-to.html">
            
                <a href="concurrent/how-to.html">
            
                    
                    线程和线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="concurrent/block-close.html">
            
                <a href="concurrent/block-close.html">
            
                    
                    线程阻塞和关闭
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="concurrent/communicate.html">
            
                <a href="concurrent/communicate.html">
            
                    
                    线程协作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="concurrent/volatile.html">
            
                <a href="concurrent/volatile.html">
            
                    
                    活性失败-volatile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="concurrent/lock.html">
            
                <a href="concurrent/lock.html">
            
                    
                    安全性失败-锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="concurrent/thread-local.html">
            
                <a href="concurrent/thread-local.html">
            
                    
                    线程局部存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="concurrent/others.html">
            
                <a href="concurrent/others.html">
            
                    
                    其他
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="collections.html">
            
                <a href="collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="nio.html">
            
                <a href="nio.html">
            
                    
                    nio
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="advance.html">
            
                <a href="advance.html">
            
                    
                    泛型，注解和反射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="mem-gc.html">
            
                <a href="mem-gc.html">
            
                    
                    内存模型和GC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="classloader.html">
            
                <a href="classloader.html">
            
                    
                    ClassLoader
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Web</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="spring.html">
            
                <a href="spring.html">
            
                    
                    spring
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">GUI</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="gui-1.html">
            
                <a href="gui-1.html">
            
                    
                    没事写个小界面什么的
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >对象管理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5BF9;&#x8C61;&#x7BA1;&#x7406;">&#x5BF9;&#x8C61;&#x7BA1;&#x7406;</h1>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#x7F16;&#x7A0B;&#x662F;&#x4E2A;&#x6162;&#x6162;&#x79EF;&#x7D2F;&#x7684;&#x8FC7;&#x7A0B;&#xFF0C;&#x5219;&#x4E0D;&#x8FBE;&#x7684;&#x535A;&#x5BA2;&#xFF0C;&#x5C31;&#x662F;&#x6211;&#x5DF2;&#x7ECF;&#x6709;&#x7684;&#xFF0C;&#x548C;&#x5C06;&#x8981;&#x6709;&#x7684;&#x79EF;&#x7D2F;&#x3002;&#x524D;&#x5341;&#x7BC7;&#x535A;&#x5BA2;&#x5927;&#x90E8;&#x5206;&#x662F;Java&#x7F16;&#x7A0B;&#x601D;&#x60F3;&#x548C;Effective Java&#x7684;&#x7B14;&#x8BB0;&#xFF0C;&#x90E8;&#x5206;&#x53C2;&#x8003;HeadFirst&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x548C;&#x5927;&#x8BDD;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x3002;</p>
<p>&#x672C;&#x8282;&#x91CD;&#x70B9;&#x8BF4;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x548C;&#x7BA1;&#x7406;&#xFF0C;&#x5982;&#x679C;&#x8FD8;&#x6709;&#x4EC0;&#x4E48;&#x8FD9;&#x65B9;&#x9762;&#x7684;&#x6B20;&#x7F3A;&#xFF0C;&#x6B22;&#x8FCE;&#x7559;&#x8A00;&#x3002;</p>
<ul>
<li>&#x76EE;&#x5F55;<ul>
<li>&#x9759;&#x6001;&#x5DE5;&#x5382;</li>
<li>&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#x6846;&#x67B6;</li>
<li>Builder&#x6A21;&#x5F0F;&#x7684;&#x6784;&#x5EFA;&#x5668;</li>
<li>&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</li>
<li>&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</li>
<li>&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</li>
<li>&#x62BD;&#x8C61;&#x5DE5;&#x5382;</li>
<li>Flyweight&#xFF1A;&#x8747;&#x91CF;&#x6A21;&#x5F0F;&#xFF08;&#x4EAB;&#x5143;&#x6A21;&#x5F0F;&#xFF09;</li>
<li>&#x5907;&#x5FD8;&#x5F55;&#x6A21;&#x5F0F;</li>
<li>&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x548C;&#x6DF1;&#x62F7;&#x8D1D;&#x6D45;&#x62F7;&#x8D1D;</li>
</ul>
</li>
</ul>
<blockquote>
<p>Effective Java&#x8FD9;&#x672C;&#x4E66;&#x91CC;&#xFF0C;&#x4F5C;&#x8005;&#x4E00;&#x76F4;&#x5728;&#x7533;&#x660E;&#x4E00;&#x6761;&#x539F;&#x5219;&#xFF1A;<br>&#x5BF9;&#x8C61;&#x4E0D;&#x80FD;&#x5728;&#x521D;&#x59CB;&#x5316;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x8FD8;&#x80FD;&#x88AB;&#x8BBF;&#x95EE;&#x5230;&#xFF0C;<br>&#x5FC5;&#x987B;&#x51C6;&#x5907;&#x597D;&#x6240;&#x6709;&#x5FC5;&#x8981;&#x5B57;&#x6BB5;&#xFF0C;&#x518D;&#x83B7;&#x53D6;&#x5BF9;&#x8C61;&#xFF0C;<br>&#x4E0D;&#x8981;&#x7559;&#x4E2D;&#x95F4;&#x72B6;&#x6001;&#x3002;</p>
</blockquote>
<h2 id="1-&#x9759;&#x6001;&#x5DE5;&#x5382;">1 &#x9759;&#x6001;&#x5DE5;&#x5382;</h2>
<p>&#x8FD9;&#x4E2A;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF0C;&#x5148;&#x4E0A;&#x4EE3;&#x7801;&#xFF1A;</p>
<h4 id="11-&#x5957;&#x8DEF;">1.1 &#x5957;&#x8DEF;</h4>
<pre><code class="lang-java">
<span class="hljs-comment">//&#x5E38;&#x89C4;&#x6A21;&#x5F0F;</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Boolean</span></span>{

    <span class="hljs-comment">//&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Boolean <span class="hljs-title">valueOf</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> b)</span></span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Boolean(b); 
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> v;

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Boolean</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> b)</span></span>{
        v = b;
    }

}

<span class="hljs-comment">//&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#xFF1A;&#x9650;&#x5236;&#x5BF9;&#x8C61;&#x7684;&#x6570;&#x76EE;&#xFF0C;&#x6BD4;&#x5982;&#x5355;&#x4F8B;&#xFF0C;&#x6B64;&#x5904;&#x7684;&#x4F8B;&#x5B50;&#x662F;&#xFF1A;Boolean&#x57FA;&#x672C;&#x5C31;&#x53EA;&#x80FD;&#x5BF9;&#x5E94;&#x4E24;&#x4E2A;&#x503C;</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Boolean</span></span>{

    <span class="hljs-comment">//&#x9884;&#x5B9A;&#x4E49;&#x7684;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x67D0;&#x79CD;&#x610F;&#x4E49;&#x4E0A;&#x7B97;&#x662F;&#x7F13;&#x5B58;&#xFF0C;&#x4F7F;&#x7528;&#x65F6;&#x53EF;&#x4EE5;&#x7701;&#x53BB;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x7684;&#x8FC7;&#x7A0B;</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Boolean True = <span class="hljs-keyword">new</span> Boolean(<span class="hljs-keyword">true</span>);
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Boolean False = <span class="hljs-keyword">new</span> Boolean(<span class="hljs-keyword">false</span>);

    <span class="hljs-comment">//&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Boolean <span class="hljs-title">valueOf</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> b)</span></span>{
        <span class="hljs-keyword">return</span> b ? True : False;
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> v;

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Boolean</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> b)</span></span>{
        v = b;
    }

}
</code></pre>
<ul>
<li><p>&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x7684;&#x597D;&#x5904;&#x662F;&#xFF1A;</p>
<ul>
<li>1 &#x65B9;&#x6CD5;&#x6709;&#x540D;&#x5B57;&#xFF0C;&#x6784;&#x9020;&#x5668;&#x6CA1;&#x6709;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x7ED9;&#x51FA;&#x4E0D;&#x540C;&#x91CD;&#x8F7D;&#xFF0C;&#x800C;&#x65B9;&#x6CD5;&#x540D;&#x8D4B;&#x4E88;&#x5176;&#x610F;&#x4E49;&#xFF0C;&#x8FD9;&#x70B9;&#x5C31;&#x80DC;&#x4E8E;&#x6784;&#x9020;&#x5668;</li>
<li>2 &#x53EF;&#x4EE5;&#x5728;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x91CC;&#x63A7;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x4E00;&#x5B9A;&#x975E;&#x5F97;&#x662F;new&#x51FA;&#x6765;&#x7684;</li>
<li>3 &#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x4EFB;&#x610F;&#x5B50;&#x7C7B;&#x578B;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x7236;&#x7C7B;&#x6216;&#x8005;&#x63A5;&#x53E3;&#x5F15;&#x7528;&#xFF0C;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x7C7B;&#x751A;&#x81F3;&#x53EF;&#x4EE5;&#x5BF9;&#x5916;&#x9690;&#x85CF;&#xFF0C;&#x53C2;&#x8003;Java Collections Framework&#x4E2D;&#x96C6;&#x5408;&#x63A5;&#x53E3;&#x7684;32&#x4E2A;&#x4FBF;&#x5229;&#x5B9E;&#x73B0;<ul>
<li>&#xFF08;1&#xFF09;Collections&#x91CC;&#x6709;unmodified, empty, checked, synchronized&#x5404;8&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x5BF9;&#x5E94;8&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x96C6;&#x5408;&#x7C7B;&#x578B;</li>
<li>&#x8FD9;8&#x79CD;&#x96C6;&#x5408;&#x7C7B;&#x578B;&#x5C31;&#x662F;&#xFF1A;Collection, List, Map, SortedMap, NavigableMap, Set, SortedSet, NavigableSet&#xFF0C;&#x6CE8;&#x610F;&#x8FD9;&#x662F;&#x63A5;&#x53E3;&#x7C7B;&#x578B;&#xFF0C;&#x5BF9;&#x5916;&#x7684;</li>
<li>&#x8FD4;&#x56DE;&#x7684;&#x5B9E;&#x9645;&#x7C7B;&#x578B;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF0C;&#x90FD;&#x662F;&#x4EE5;private static class&#x7684;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5E76;&#x672A;&#x5BF9;&#x5916;&#x516C;&#x5F00;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;jdk&#x968F;&#x65F6;&#x4FEE;&#x6539;&#xFF0C;&#x63D0;&#x5347;&#x6027;&#x80FD;&#x6216;&#x4FEE;&#x6539;&#x5B9E;&#x73B0;</li>
<li>&#xFF08;2&#xFF09;EnumSet&#xFF1A;&#x5176;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x4F1A;&#x6839;&#x636E;&#x5E95;&#x5C42;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x5927;&#x5C0F;&#xFF0C;&#x8FD4;&#x56DE;RegalarEnumSet&#x5BF9;&#x8C61;&#x6216;&#x8005;JumboEnumSet&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x4E14;&#x8FD9;&#x5BF9;&#x5916;&#x90E8;&#x7528;&#x6237;&#x662F;&#x9690;&#x85CF;&#x7684;</li>
</ul>
</li>
<li>4 &#x7B80;&#x5316;Map<string, string=""> m = new HashMap<string, string="">()&#x8FD9;&#x79CD;&#x7E41;&#x7410;&#x7684;&#x8C03;&#x7528;, Map<string, string=""> m = HashMap.newHashMap();</string,></string,></string,></li>
</ul>
</li>
<li><p>&#x9759;&#x6001;&#x5DE5;&#x5382;&#x7684;&#x547D;&#x540D;&#x6709;&#x51E0;&#x4E2A;&#x5957;&#x8DEF;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x522B;&#x4EBA;&#x4E00;&#x770B;&#x5230;&#x65B9;&#x6CD5;&#x540D;&#xFF0C;&#x5C31;&#x77E5;&#x9053;&#x662F;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</p>
<ul>
<li>&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x7EC8;&#x7A76;&#x4E5F;&#x53EA;&#x662F;&#x666E;&#x901A;&#x7684;static&#x65B9;&#x6CD5;&#xFF0C;&#x6587;&#x6863;&#x4E2D;&#x5E76;&#x4E0D;&#x4F1A;&#x7279;&#x522B;&#x5BF9;&#x5F85;&#xFF0C;&#x8FD9;&#x662F;&#x4E2A;&#x7F3A;&#x70B9;</li>
<li>&#x6240;&#x4EE5;&#x8FD9;&#x91CC;&#x6709;&#x4E9B;&#x547D;&#x540D;&#x5957;&#x8DEF;&#xFF0C;&#x8FD8;&#x662F;&#x5E94;&#x8BE5;&#x9075;&#x5B88;&#x7684;</li>
<li>valueOf&#xFF1A;&#x7C7B;&#x4F3C;Boolean.valueOf()&#xFF0C;&#x5B9E;&#x9645;&#x662F;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF0C;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x7684;&#x5B9E;&#x4F8B;&#x6709;&#x76F8;&#x540C;&#x7684;&#x503C;</li>
<li>of&#xFF1A;valueOf&#x7684;&#x7B80;&#x6D01;&#x5199;&#x6CD5;&#xFF0C;&#x5728;EnumSet&#x4E2D;&#x6D41;&#x884C;&#x8D77;&#x6765;</li>
<li>getInstance&#xFF1A;&#x53C2;&#x6570;&#x53EF;&#x9009;</li>
<li>newInstance&#xFF1A;&#x9690;&#x542B;&#x7684;&#x610F;&#x601D;&#x662F;&#x6BCF;&#x6B21;&#x90FD;&#x662F;new&#x4E00;&#x4E2A;&#x65B0;&#x7684;</li>
<li>getType, newType</li>
</ul>
</li>
</ul>
<h2 id="2-&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#x6846;&#x67B6;">2 &#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#x6846;&#x67B6;</h2>
<p>&#x8FD9;&#x662F;&#x4ECE;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x597D;&#x5904;3&#x91CC;&#x5F15;&#x51FA;&#x6765;&#x7684;&#xFF0C;&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x4F9D;&#x8D56;&#x4E8E;&#x6B64;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F46;&#x5E76;&#x4E0D;&#x5173;&#x5FC3;&#x5177;&#x4F53;&#x5B9E;&#x73B0;</p>
<ul>
<li>&#x4E09;&#x5927;&#x7EC4;&#x4EF6;&#xFF1A;&#x4EE5;JDBC&#x4E3A;&#x4F8B;<ul>
<li><code>&#x670D;&#x52A1;&#x63A5;&#x53E3;</code>&#xFF1A;Service Interface&#xFF0C;&#x63D0;&#x4F9B;&#x8005;&#x5B9E;&#x73B0;&#xFF0C;&#x5982;Connection</li>
<li><code>&#x63D0;&#x4F9B;&#x8005;&#x6CE8;&#x518C;API</code>&#xFF1A;Provider Registreation API&#xFF0C;&#x7528;&#x6765;&#x6CE8;&#x518C;&#x5B9E;&#x73B0;&#xFF0C;&#x8BA9;&#x5BA2;&#x6237;&#x7AEF;&#x8BBF;&#x95EE;&#xFF0C;&#x5982;DriverManager.registerDriver()</li>
<li><code>&#x670D;&#x52A1;&#x8BBF;&#x95EE;API</code>&#xFF1A;Service Access API&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x7528;&#x6765;&#x83B7;&#x53D6;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#xFF0C;&#x8FD9;&#x91CC;&#x5C31;&#x662F;&#x7075;&#x6D3B;&#x7684;&#x9759;&#x6001;&#x5DE5;&#x5382;&#xFF0C;&#x5982;DriverManager.getConnection()</li>
<li><code>&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#x63A5;&#x53E3;</code>&#xFF0C;Service Provider Interface&#xFF0C;&#x53EF;&#x9009;&#xFF0C;&#x7528;&#x6765;&#x521B;&#x5EFA;&#x670D;&#x52A1;&#x5B9E;&#x4F8B;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8FD9;&#x4E2A;&#xFF0C;&#x5C31;&#x5F97;&#x6309;&#x7167;&#x7C7B;&#x540D;&#x6CE8;&#x518C;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x53CD;&#x5C04;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x5982;Driver&#x5C31;&#x662F;&#x8FD9;&#x4E2A;&#x89D2;&#x8272;</li>
</ul>
</li>
</ul>
<pre><code class="lang-java">
<span class="hljs-comment">/**
 * ================&#x670D;&#x52A1;&#x63A5;&#x53E3;&#xFF1A;Service Interface==================
 * &#x4E00;&#x4E2A;&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x540C;&#x60C5;&#x51B5;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x4E0D;&#x540C;&#x7684;Service&#x5BF9;&#x8C61;&#xFF0C;
 * &#x5373;&#x901A;&#x8FC7;Service&#x7684;&#x4E0D;&#x540C;&#x5B9E;&#x73B0;&#xFF0C;&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;
 *
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Service</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">doService</span><span class="hljs-params">()</span></span>;

}


<span class="hljs-comment">/**
 * ================&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#x63A5;&#x53E3;==================
 * &#x7528;&#x6765;&#x751F;&#x6210;Service&#x5BF9;&#x8C61;&#xFF0C;&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x4F7F;&#x7528;Provider&#xFF0C;&#x5219;&#x6CE8;&#x518C;&#x5230;Services&#x7684;&#x5C31;&#x5F97;&#x662F;Service&#x5B9E;&#x73B0;&#x7C7B;&#x7684;Class&#x5BF9;&#x8C61;&#xFF0C;
 * newInstance&#x4E5F;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x53CD;&#x5C04;&#x6765;&#x4E86;
 * &#x95EE;&#x9898;&#x5C31;&#x662F;Provider&#x5B9E;&#x73B0;&#x7C7B;&#x5E94;&#x8BE5;&#x6709;&#x51E0;&#x4E2A;
 *
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Provider</span> </span>{
    <span class="hljs-function">Service <span class="hljs-title">newService</span><span class="hljs-params">()</span></span>;
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Services</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Services</span><span class="hljs-params">()</span></span>{}

    <span class="hljs-comment">//================&#x63D0;&#x4F9B;&#x8005;&#x6CE8;&#x518C;API==================//</span>
    <span class="hljs-comment">//&#x8FD9;&#x91CC;&#x8981;&#x4E48;&#x6CE8;&#x518C;provider&#x5BF9;&#x8C61;&#xFF0C;&#x8981;&#x4E48;&#x6CE8;&#x518C;Service&#x5B9E;&#x73B0;&#x7C7B;&#x7684;Class&#xFF0C;&#x4F60;&#x9009;&#x5427;</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Map&lt;String, Provider&gt; providers = <span class="hljs-keyword">new</span> ConcurrentHashMap&lt;&gt;();
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String DEFAULT_PROVIDER_NAME = <span class="hljs-string">&quot;&lt;def&gt;&quot;</span>;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">registerDefaultProvider</span><span class="hljs-params">(Provider p)</span></span>{
        registerProvider(DEFAULT_PROVIDER_NAME, p);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">registerProvider</span><span class="hljs-params">(String defaultProviderName, Provider p)</span> </span>{
        providers.put(defaultProviderName, p);
    }

    <span class="hljs-comment">//================&#x670D;&#x52A1;&#x8BBF;&#x95EE;API==================//</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Service <span class="hljs-title">newInstance</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> newInstance(DEFAULT_PROVIDER_NAME);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Service <span class="hljs-title">newInstance</span><span class="hljs-params">(String name)</span> </span>{
        Provider p = providers.get(name);
        <span class="hljs-keyword">if</span>(p == <span class="hljs-keyword">null</span>){
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalArgumentException(<span class="hljs-string">&quot;No provider registered with name + &quot;</span> + name);
        }
        <span class="hljs-keyword">return</span> p.newService();
    }
}
</code></pre>
<ul>
<li>&#x4F7F;&#x7528;&#x573A;&#x666F;<ul>
<li>Service&#x63D0;&#x4F9B;&#x4E86;&#x67D0;&#x9879;&#x5DE5;&#x4F5C;&#x7684;&#x63A5;&#x53E3;</li>
<li>Services&#x662F;&#x4E00;&#x4E2A;&#x5E73;&#x53F0;&#xFF1A;<ul>
<li>&#x6CE8;&#x518C;&#x63A5;&#x53E3;&#xFF1A;&#x7528;&#x4E8E;&#x6CE8;&#x518C;Service&#x7684;&#x5B9E;&#x73B0;<ul>
<li>&#x53EF;&#x4EE5;&#x6CE8;&#x518C;Provider&#xFF0C;&#x5982;&#x4E0A;&#x4F8B;&#xFF0C;&#x89C4;&#x907F;&#x8C03;&#x7528;Class&#x5BF9;&#x8C61;&#x548C;&#x53CD;&#x5C04;</li>
<li>&#x53EF;&#x4EE5;&#x6CE8;&#x518C;Service&#x5B9E;&#x73B0;&#x7C7B;&#x7684;Class&#x5BF9;&#x8C61;</li>
<li>&#x53EF;&#x4EE5;&#x6CE8;&#x518C;Service&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;</li>
<li>&#x8BBF;&#x95EE;&#x63A5;&#x53E3;&#xFF1A;&#x7528;&#x4E8E;&#x83B7;&#x53D6;Service&#x7684;&#x5B9E;&#x73B0;&#x7684;&#x5B9E;&#x4F8B;</li>
</ul>
</li>
<li>api&#x4F5C;&#x8005;&#x548C;&#x7528;&#x6237;&#x90FD;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;Service&#x548C;Provider&#xFF0C;&#x5373;&#x63D0;&#x4F9B;&#x670D;&#x52A1;</li>
<li>JDBC&#x7684;&#x670D;&#x52A1;&#x5C31;&#x662F;&#x8FDE;&#x63A5;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x4E0D;&#x540C;&#x7684;Service&#x5B9E;&#x73B0;&#xFF0C;&#x5BF9;&#x5E94;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x4E5F;&#x4F7F;&#x7528;&#x4E86;&#x4E0D;&#x540C;&#x7684;&#x9A71;&#x52A8;</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="3-builder&#x6A21;&#x5F0F;&#x7684;&#x6784;&#x5EFA;&#x5668;">3 Builder&#x6A21;&#x5F0F;&#x7684;&#x6784;&#x5EFA;&#x5668;</h2>
<ul>
<li>&#x4F7F;&#x7528;&#x573A;&#x666F;&#xFF1A;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x591A;<ul>
<li>&#x539F;&#x59CB;&#x6A21;&#x5F0F;&#xFF1A;&#x6784;&#x9020;&#x5668;&#x6216;&#x8005;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x5F62;&#x5F0F;&#x592A;&#x591A;&#xFF0C;&#x53C2;&#x6570;&#x591A;</li>
<li>JavaBeans&#x6A21;&#x5F0F;&#xFF1A;new&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x7136;&#x540E;set&#x5404;&#x79CD;&#x53C2;&#x6570;&#xFF0C;&#x4EE3;&#x7801;&#x4E0D;&#x5B9C;&#x7BA1;&#x7406;&#xFF0C;set&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x5BF9;&#x8C61;&#x4E5F;&#x53EF;&#x80FD;&#x5904;&#x4E8E;&#x4E0D;&#x4E00;&#x81F4;&#x72B6;&#x6001;</li>
<li>&#x628A;JavaBeans&#x7684;&#x4E00;&#x7EC4;set&#x5C01;&#x88C5;&#x8D77;&#x6765;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;&#x7684;&#x539F;&#x59CB;&#x5F62;&#x6001;&#xFF0C;&#x4F46;&#x91CC;&#x9762;&#x4F9D;&#x65E7;&#x9700;&#x8981;&#x5BF9;&#x5BF9;&#x8C61;&#x7684;&#x4E00;&#x81F4;&#x6027;&#x8D1F;&#x8D23;<ul>
<li>&#x8FD9;&#x91CC;&#x8BF4;&#x7684;&#x4E00;&#x81F4;&#x6027;&#x95EE;&#x9898;&#xFF0C;&#x610F;&#x601D;&#x662F;new&#x5B8C;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x4E00;&#x7EC4;set&#x4E4B;&#x540E;&#xFF0C;&#x5BF9;&#x8C61;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#xFF0C;</li>
<li>&#x4F46;set&#x671F;&#x95F4;&#xFF0C;&#x5BF9;&#x8C61;&#x5DF2;&#x7ECF;&#x6709;&#x4E86;&#xFF0C;&#x5374;&#x4E0D;&#x80FD;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5371;&#x9669;&#x7684;&#x72B6;&#x6001;</li>
<li>Builder&#x6A21;&#x5F0F;&#xFF0C;&#x5C31;&#x4E0D;&#x5B58;&#x5728;&#x8FD9;&#x4E2A;&#x4E0D;&#x4E00;&#x81F4;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x56E0;&#x4E3A;&#x5BF9;&#x8C61;&#x6700;&#x7EC8;&#x8FD8;&#x662F;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x5668;&#x51FA;&#x6765;&#x540E;&#x5C31;&#x5DF2;&#x7ECF;&#x53EF;&#x4EE5;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#x4E86;</li>
</ul>
</li>
<li>&#x6240;&#x4EE5;&#x8FD9;&#x65F6;&#x4F7F;&#x7528;Builder&#x6A21;&#x5F0F;&#xFF0C;&#x65E2;&#x80FD;&#x4FDD;&#x8BC1;JavaBeans&#x7684;&#x53EF;&#x8BFB;&#x6027;&#xFF0C;&#x53C8;&#x80FD;&#x4FDD;&#x8BC1;&#x539F;&#x59CB;&#x6A21;&#x5F0F;&#x7684;&#x5B89;&#x5168;&#x6027;</li>
<li>ImageLoader&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;AlertDialog&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x90FD;&#x4F7F;&#x7528;&#x4E86;&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#xFF0C;&#x53C2;&#x6570;&#x5F88;&#x591A;&#xFF0C;&#x6709;&#x4E9B;&#x5FC5;&#x586B;&#xFF08;&#x653E;&#x5230;Buidler&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x6709;&#x4E9B;&#x9009;&#x586B;&#xFF08;&#x4F5C;&#x4E3A;&#x5355;&#x72EC;&#x65B9;&#x6CD5;&#xFF09;</li>
</ul>
</li>
</ul>
<h3 id="31-&#x7B80;&#x5355;&#x6A21;&#x5F0F;">3.1 &#x7B80;&#x5355;&#x6A21;&#x5F0F;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NutritionFacts</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servingSize;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servings;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> calories;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> fat;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> sodium;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> carbohydrate;


    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">NutritionFacts</span><span class="hljs-params">(Builder builder)</span> </span>{
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Builder</span></span>{

        <span class="hljs-comment">//&#x5FC5;&#x586B;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x65E0;&#x9ED8;&#x8BA4;&#x503C;</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servingSize;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servings;

        <span class="hljs-comment">//&#x9009;&#x586B;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6709;&#x9ED8;&#x8BA4;&#x503C;</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> calories = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> fat      = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> carbohydrate = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> sodium = <span class="hljs-number">0</span>;

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Builder</span><span class="hljs-params">(<span class="hljs-keyword">int</span> servingSize, <span class="hljs-keyword">int</span> servings)</span></span>{
            <span class="hljs-keyword">this</span>.servingSize = servingSize;
            <span class="hljs-keyword">this</span>.servings = servings;
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> Builder <span class="hljs-title">calories</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ calories = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }
        <span class="hljs-function"><span class="hljs-keyword">public</span> Builder <span class="hljs-title">fat</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ fat = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }
        <span class="hljs-function"><span class="hljs-keyword">public</span> Builder <span class="hljs-title">carbohydrate</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ carbohydrate = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;}
        <span class="hljs-function"><span class="hljs-keyword">public</span> Builder <span class="hljs-title">sodium</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ sodium = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }

        <span class="hljs-function"><span class="hljs-keyword">public</span> NutritionFacts <span class="hljs-title">build</span><span class="hljs-params">()</span></span>{
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> NutritionFacts(<span class="hljs-keyword">this</span>);
        }

    }

}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
    NutritionFacts cocacola = <span class="hljs-keyword">new</span> NutritionFacts.Builder(<span class="hljs-number">240</span>,  <span class="hljs-number">8</span>)
            .calories(<span class="hljs-number">100</span>)
            .sodium(<span class="hljs-number">35</span>)
            .carbohydrate(<span class="hljs-number">27</span>)
            .build();
}
</code></pre>
<h3 id="32-builder&#x63A5;&#x53E3;&#x6A21;&#x5F0F;">3.2 Builder&#x63A5;&#x53E3;&#x6A21;&#x5F0F;</h3>
<p>&#x5C06;Builder&#x62BD;&#x53D6;&#x51FA;&#x6765;&#x5355;&#x72EC;&#x505A;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x7684;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#xFF1A;</p>
<ul>
<li>&#x521B;&#x5EFA;&#x4EFB;&#x610F;&#x591A;&#x7684;&#x5BF9;&#x8C61;</li>
<li>&#x5176;&#x529F;&#x80FD;&#x5C31;&#x7C7B;&#x4F3C;&#x4E8E;&#x76F4;&#x63A5;&#x4F20;Class&#x5BF9;&#x8C61;</li>
<li>&#x4F46;&#x6BD4;Class&#x5BF9;&#x8C61;&#x7684;newInstance&#x65B9;&#x6CD5;&#x591A;&#x4E86;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#xFF0C;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x4FDD;&#x8BC1;&#x7B49;</li>
<li>&#x7F3A;&#x70B9;&#x5C31;&#x662F;&#x8981;&#x521B;&#x5EFA;N&#x591A;&#x4E2A;Builder&#x7C7B;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Builder</span>&lt;<span class="hljs-title">T</span>&gt; </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> T <span class="hljs-title">build</span><span class="hljs-params">()</span></span>;
}


<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NutritionFacts2</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servingSize;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servings;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> calories;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> fat;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> sodium;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> carbohydrate;


    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">NutritionFacts2</span><span class="hljs-params">(MyBuilder builder)</span> </span>{
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyBuilder</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Builder</span>&lt;<span class="hljs-title">NutritionFacts2</span>&gt;</span>{

        <span class="hljs-comment">//&#x5FC5;&#x586B;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x65E0;&#x9ED8;&#x8BA4;&#x503C;</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servingSize;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> servings;

        <span class="hljs-comment">//&#x9009;&#x586B;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6709;&#x9ED8;&#x8BA4;&#x503C;</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> calories = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> fat      = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> carbohydrate = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> sodium = <span class="hljs-number">0</span>;

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyBuilder</span><span class="hljs-params">(<span class="hljs-keyword">int</span> servingSize, <span class="hljs-keyword">int</span> servings)</span></span>{
            <span class="hljs-keyword">this</span>.servingSize = servingSize;
            <span class="hljs-keyword">this</span>.servings = servings;
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> MyBuilder <span class="hljs-title">calories</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ calories = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }
        <span class="hljs-function"><span class="hljs-keyword">public</span> MyBuilder <span class="hljs-title">fat</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ fat = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }
        <span class="hljs-function"><span class="hljs-keyword">public</span> MyBuilder <span class="hljs-title">carbohydrate</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ carbohydrate = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;}
        <span class="hljs-function"><span class="hljs-keyword">public</span> MyBuilder <span class="hljs-title">sodium</span><span class="hljs-params">(<span class="hljs-keyword">int</span> val)</span></span>{ sodium = val; <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; }

        <span class="hljs-function"><span class="hljs-keyword">public</span> NutritionFacts2 <span class="hljs-title">build</span><span class="hljs-params">()</span></span>{
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> NutritionFacts2(<span class="hljs-keyword">this</span>);
        }

    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Builder&lt;NutritionFacts2&gt; builder = <span class="hljs-keyword">new</span> NutritionFacts2.MyBuilder(<span class="hljs-number">240</span>,  <span class="hljs-number">8</span>)
                .calories(<span class="hljs-number">100</span>)
                .sodium(<span class="hljs-number">35</span>)
                .carbohydrate(<span class="hljs-number">27</span>);

        NutritionFacts2 cocacola = builder.build();
    }
}

<span class="hljs-comment">/*
&#x8FD9;&#x91CC;&#x7684;Builder&lt;NutritionFacts2&gt; builder&#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x4EE5;&#x4F20;&#x7ED9;&#x4EFB;&#x610F;&#x7684;&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;
*/</span>
</code></pre>
<h2 id="4-&#x5355;&#x4F8B;&#x6A21;&#x5F0F;">4 &#x5355;&#x4F8B;&#x6A21;&#x5F0F;</h2>
<ul>
<li>&#x600E;&#x4E48;&#x80FD;&#x7834;&#x574F;&#x5355;&#x4F8B;&#x7684;&#x9650;&#x5236;<ul>
<li>&#x53CD;&#x5C04;&#xFF1A;&#x53CD;&#x5C04;&#x51FA;&#x79C1;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;Enum&#x53EF;&#x81EA;&#x7136;&#x89C4;&#x907F;&#x6B64;&#x95EE;&#x9898;&#xFF0C;&#x5176;&#x4ED6;&#x65B9;&#x5F0F;&#x5F97;&#x5F3A;&#x5199;&#x68C0;&#x67E5;&#x4EE3;&#x7801;</li>
<li>&#x5E8F;&#x5217;&#x5316;&#xFF1A;&#x5C06;&#x5355;&#x4F8B;&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x518D;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x51FA;&#x6765;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;Enum&#x53EF;&#x81EA;&#x7136;&#x89E3;&#x51B3;&#xFF0C;&#x5176;&#x4ED6;&#x65B9;&#x5F0F;&#x4F7F;&#x7528;readResolve&#x65B9;&#x6CD5;</li>
<li>&#x5B89;&#x5353;&#x91CC;&#x7684;&#x591A;&#x8FDB;&#x7A0B;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x591A;&#x4E2A;Application</li>
</ul>
</li>
</ul>
<h3 id="41-&#x997F;&#x6C49;&#xFF1A;&#x516C;&#x6709;&#x57DF;&#xFF0C;&#x6216;&#x9759;&#x6001;&#x5DE5;&#x5382;">4.1 &#x997F;&#x6C49;&#xFF1A;&#x516C;&#x6709;&#x57DF;&#xFF0C;&#x6216;&#x9759;&#x6001;&#x5DE5;&#x5382;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Singleton</span> </span>{

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Singleton INSTANCE = <span class="hljs-keyword">new</span> Singleton();
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Singleton</span><span class="hljs-params">()</span></span>{}
    <span class="hljs-function"><span class="hljs-keyword">private</span> Object <span class="hljs-title">readResolve</span><span class="hljs-params">()</span></span>{ <span class="hljs-keyword">return</span> INSTANCE; }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">provideService</span><span class="hljs-params">()</span></span>{

    }

}

<span class="hljs-comment">//&#x8BBF;&#x95EE;</span>
Singleton.INSTANCE.provideService();
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Singleton</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Singleton INSTANCE = <span class="hljs-keyword">new</span> Singleton();
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Singleton</span><span class="hljs-params">()</span></span>{}
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title">getInstance</span><span class="hljs-params">()</span></span>{ <span class="hljs-keyword">return</span> INSTANCE; }
    <span class="hljs-function"><span class="hljs-keyword">private</span> Object <span class="hljs-title">readResolve</span><span class="hljs-params">()</span></span>{ <span class="hljs-keyword">return</span> INSTANCE; }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">provideService</span><span class="hljs-params">()</span></span>{

    }

}

<span class="hljs-comment">//&#x8BBF;&#x95EE;</span>
Singleton.getInstance().provideService();
</code></pre>
<h3 id="42-&#x61D2;&#x6C49;&#xFF1A;&#x53CC;&#x4FDD;&#x9669;&#x6A21;&#x5F0F;">4.2 &#x61D2;&#x6C49;&#xFF1A;&#x53CC;&#x4FDD;&#x9669;&#x6A21;&#x5F0F;</h3>
<p>&#x8FD9;&#x91CC;&#x6CE8;&#x610F;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#x548C;volatile&#x7684;&#x4F7F;&#x7528;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Singleton</span></span>{
   <span class="hljs-keyword">private</span> <span class="hljs-keyword">volatile</span> <span class="hljs-keyword">static</span> Singleton instance = <span class="hljs-keyword">null</span>;
   <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Singleton</span><span class="hljs-params">()</span></span>{}
   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title">getInstance</span><span class="hljs-params">()</span></span>{
     <span class="hljs-keyword">if</span>(instance == <span class="hljs-keyword">null</span>){
        <span class="hljs-keyword">synchronized</span>(Singleton.class){
            <span class="hljs-keyword">if</span>(instance == <span class="hljs-keyword">null</span>){ instance = <span class="hljs-keyword">new</span> Singleton(); }
        }
     }
     <span class="hljs-keyword">return</span> instance;
   }
}
</code></pre>
<p>&#x8FD9;&#x53CC;&#x91CD;&#x68C0;&#x67E5;&#x7684;&#x6982;&#x5FF5;&#x53EF;&#x4EE5;&#x63A8;&#x5E7F;&#x5230;&#x6240;&#x6709;&#x9700;&#x8981;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x9700;&#x8981;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#xFF0C;
&#x90A3;&#x8BBF;&#x95EE;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F60;&#x5C31;&#x5E94;&#x8BE5;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-java">
<span class="hljs-keyword">private</span> <span class="hljs-keyword">volatile</span> T field;

<span class="hljs-function">T <span class="hljs-title">getField</span><span class="hljs-params">()</span></span>{
    <span class="hljs-comment">//&#x7528;&#x5230;&#x4E86;result&#x8FD9;&#x4E2A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x786E;&#x4FDD;field&#x53EA;&#x5728;&#x5DF2;&#x7ECF;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8BFB;&#x53D6;&#x4E00;&#x6B21;&#xFF0C;&#x53EF;&#x4EE5;&#x63D0;&#x5347;&#x6027;&#x80FD;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>
    <span class="hljs-comment">//&#x636E;&#x8BF4; &#x901F;&#x5EA6;&#x6BD4;&#x4E0D;&#x7528;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x5FEB;&#x4E86;25%</span>
    T result = field;  
    <span class="hljs-keyword">if</span>(result == <span class="hljs-keyword">null</span>){
        <span class="hljs-keyword">synchronized</span>(<span class="hljs-keyword">this</span>){
            result = field;
            <span class="hljs-keyword">if</span>(result == <span class="hljs-keyword">null</span>){
                field = result = computeFieldValue();
            }
        }
    }
    <span class="hljs-keyword">return</span> result;
}
</code></pre>
<h3 id="43-&#x61D2;&#x6C49;&#xFF1A;&#x5185;&#x90E8;&#x7C7B;&#x6A21;&#x5F0F;">4.3 &#x61D2;&#x6C49;&#xFF1A;&#x5185;&#x90E8;&#x7C7B;&#x6A21;&#x5F0F;</h3>
<p>&#x8FD9;&#x91CC;&#x7684;&#x8BF4;&#x6CD5;&#x662F;&#xFF1A;<br>SingletonHolder&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x4F1A;&#x5728;&#x8BBF;&#x95EE;&#x65F6;&#x88AB;&#x52A0;&#x8F7D;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x91CC;&#x5B9E;&#x73B0;&#x4E86;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#xFF0C;&#x5E76;&#x4E14;&#x5185;&#x90E8;&#x7C7B;&#x53EF;&#x4EE5;&#x4ECE;&#x8BED;&#x8A00;&#x5C42;&#x9762;&#x4E0A;&#x9632;&#x6B62;&#x591A;&#x7EBF;&#x7A0B;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6BD4;&#x53CC;&#x91CD;&#x9501;&#x6A21;&#x5F0F;&#x4F18;&#x96C5;&#x7684;&#x591A;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Singleton</span></span>{
   <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SingletonHolder</span></span>{
       <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Singleton INSTANCE = <span class="hljs-keyword">new</span> Singleton();
   }
   <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Singleton</span><span class="hljs-params">()</span></span>{}
   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title">getInstance</span><span class="hljs-params">()</span></span>{
       <span class="hljs-keyword">return</span> SingletonHolder.INSTANCE;
   }
}
</code></pre>
<p>&#x8BBF;&#x95EE;Singleton&#x8FD9;&#x4E2A;&#x7C7B;&#x65F6;&#xFF0C;&#x624D;&#x52A0;&#x8F7D;Inner&#xFF0C;&#x5355;&#x4F8B;&#x624D;&#x88AB;&#x521D;&#x59CB;&#x5316;<br>&#x800C;&#x4E14;&#x4E00;&#x4E2A;Inner&#x4FDD;&#x8BC1;&#x4E86;&#x6709;&#x4E00;&#x4E2A;singleton&#x9759;&#x6001;&#x5B9E;&#x4F8B;<br>&#x90A3;&#x80FD;&#x4FDD;&#x8BC1;Inner&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x5417;&#xFF1F;&#x80FD;&#x554A;&#xFF0C;ClassLoader&#x4F1A;&#x4FDD;&#x8BC1;Inner&#x7684;Class&#x5C31;&#x4E00;&#x4E2A;  </p>
<h3 id="44-&#x679A;&#x4E3E;">4.4 &#x679A;&#x4E3E;</h3>
<p>&#x6309;&#x7167;Effective Java&#x4E66;&#x91CC;&#x8BF4;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x867D;&#x7136;&#x6CA1;&#x6D41;&#x884C;&#x8D77;&#x6765;&#xFF0C;&#x4F46;&#x6700;&#x7B26;&#x5408;&#x5355;&#x4F8B;&#x7684;&#x9700;&#x6C42;</p>
<pre><code class="lang-java"><span class="hljs-comment">//&#x76F4;&#x63A5;&#x5C31;&#x80FD;&#x9632;&#x6B62;&#x53CD;&#x5C04;&#xFF0C;&#x9632;&#x6B62;&#x5E8F;&#x5217;&#x5316;&#x65F6;&#x751F;&#x6210;&#x65B0;&#x7C7B;</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> Singleton {

    INSTANCE;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">provideService</span><span class="hljs-params">()</span></span>{

    }

}
</code></pre>
<h3 id="45-&#x66B4;&#x529B;&#x53CD;&#x5C04;&#x7248;&#x7684;&#x5355;&#x4F8B;&#xFF1A;&#x8DA3;&#x5473;&#x63A2;&#x7D22;">4.5 &#x66B4;&#x529B;&#x53CD;&#x5C04;&#x7248;&#x7684;&#x5355;&#x4F8B;&#xFF1A;&#x8DA3;&#x5473;&#x63A2;&#x7D22;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Singleton</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">Singleton</span><span class="hljs-params">()</span></span>{}
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doSth</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x505A;&#x70B9;&#x4EC0;&#x4E48;&quot;</span>);
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SingletonFactory</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singleton singleton;
    <span class="hljs-comment">//===&#x53EA;&#x5B9E;&#x4F8B;&#x5316;&#x4E00;&#x6B21;&#xFF0C;&#x4F7F;&#x7528;&#x66B4;&#x529B;&#x53CD;&#x5C04;</span>
    <span class="hljs-keyword">static</span>{
        <span class="hljs-keyword">try</span> {
            Class cls = Class.forName(Singleton.class.getName());
            Constructor cons = cls.getDeclaredConstructor();
            cons.setAccessible(<span class="hljs-keyword">true</span>);
            singleton = (Singleton) cons.newInstance();
        } <span class="hljs-keyword">catch</span> (Exception e) {
            e.printStackTrace();
        }
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title">getSingleton</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> singleton;
    }

    <span class="hljs-comment">/**
     * &#x6269;&#x5C55;&#xFF1A;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#x53EF;&#x4EE5;&#x6709;&#x4E00;&#x4E2A;&#x5355;&#x4F8B;&#x6784;&#x9020;&#x5668;&#xFF0C;&#x8D1F;&#x8D23;&#x751F;&#x6210;&#x6240;&#x6709;&#x5355;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x4F20;&#x5165;&#x7C7B;&#x578B;&#xFF0C;
     * &#x4F46;&#x662F;&#x9700;&#x8981;&#x4E8B;&#x5148;&#x77E5;&#x9053;&#x6709;&#x51E0;&#x4E2A;&#x5355;&#x4F8B;&#x7C7B;&#x578B;
     */</span>
}
</code></pre>
<h2 id="5-&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;">5 &#x7B80;&#x5355;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</h2>
<p>&#x573A;&#x666F;&#xFF1A;&#x62AB;&#x8428;&#x5E97;&#x91CC;&#x751F;&#x4EA7;&#x5404;&#x79CD;&#x62AB;&#x8428;&#xFF0C;&#x9700;&#x8981;&#x4F60;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x70B9;&#x9910;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x62AB;&#x8428;&#x7C7B;&#x578B;</p>
<pre><code class="lang-java">&#x5148;&#x7ED9;&#x51FA;Pizza&#x7684;&#x7C7B;&#x4F53;&#x7CFB;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheesePizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PepperoniPizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClamPizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">VeggiPizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">//------------------------------------------------------------</span>
<span class="hljs-comment">//&#x7B2C;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x4E0D;&#x7528;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</span>
<span class="hljs-comment">//------------------------------------------------------------</span>
<span class="hljs-function">Pizza <span class="hljs-title">orderPizza</span><span class="hljs-params">(String type)</span></span>{
    Pizza pizza;
    <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
        pizza = <span class="hljs-keyword">new</span> CheesePizza();
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;pepperoni&quot;</span>)){
        pizza = <span class="hljs-keyword">new</span> PepperoniPizza();
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;clam&quot;</span>)){
        pizza = <span class="hljs-keyword">new</span> ClamPizza();
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggie&quot;</span>)){
        pizza = <span class="hljs-keyword">new</span> VeggiPizza();
    }
    pizza.prepare();
    pizza.bake();
    pizza.cut();
    pizza.box();
    <span class="hljs-keyword">return</span> pizza;
}
<span class="hljs-comment">//&#x5982;&#x679C;&#x9700;&#x8981;&#x589E;&#x5220;pizza&#x7684;&#x79CD;&#x7C7B;&#xFF0C;&#x5219;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x4EE3;&#x7801;&#x9700;&#x8981;&#x4FEE;&#x6539;</span>
<span class="hljs-comment">//&#x4E5F;&#x5C31;&#x662F;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x5DF2;&#x7ECF;&#x7F16;&#x8BD1;&#x597D;&#x7684;</span>
<span class="hljs-comment">//&#x4E0D;&#x7B26;&#x5408;&#x5BF9;&#x4FEE;&#x6539;&#x5173;&#x95ED;&#xFF0C;&#x5BF9;&#x6269;&#x5C55;&#x5F00;&#x653E;&#x7684;&#x539F;&#x5219;</span>

<span class="hljs-comment">//------------------------------------------------------------</span>
<span class="hljs-comment">//&#x7B2C;&#x4E8C;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x4F7F;&#x7528;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</span>
<span class="hljs-comment">//------------------------------------------------------------</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SimplePizzaFactory</span></span>{

        <span class="hljs-comment">///&#x65B9;&#x5F0F;1&#xFF1A;&#x4F20;&#x5165;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x7684;type&#xFF0C;&#x6216;&#x8005;int&#x7C7B;&#x578B;&#x7684;type&#xFF0C;&#x4F9D;&#x7136;&#x9700;&#x8981;&#x4FEE;&#x6539;&#xFF0C;&#x4F46;&#x81F3;&#x5C11;&#x4EE3;&#x7801;&#x5DF2;&#x7ECF;&#x90FD;&#x5F52;&#x5230;&#x4E00;&#x4E2A;&#x5730;&#x65B9;&#x4E86;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
        <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CheesePizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;pepperoni&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> PepperoniPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;clam&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> ClamPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggie&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> VeggiPizza();
        }
        <span class="hljs-keyword">return</span> pizza;
    }

        <span class="hljs-comment">///&#x65B9;&#x5F0F;2&#xFF1A;&#x518D;&#x589E;&#x52A0;&#x65B0;&#x7684;pizza&#x7C7B;&#x578B;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E5F;&#x4E0D;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E86;</span>
        <span class="hljs-keyword">public</span> &lt;T extends Pizza&gt; <span class="hljs-function">T <span class="hljs-title">createPizza</span><span class="hljs-params">(Class&lt;T&gt; clazz)</span></span>{
        Pizza pizza;
        <span class="hljs-keyword">try</span>{
            pizza = clazz.newInstance();
        }<span class="hljs-keyword">catch</span>(Exception e){
            e.printStackTrace();
            System.out.println(<span class="hljs-string">&quot;&#x751F;&#x6210;&#x9519;&#x8BEF;&quot;</span>);
        }
        <span class="hljs-keyword">return</span> (T)pizza;
    }

       <span class="hljs-comment">///&#x65B9;&#x5F0F;3&#xFF1A;&#x53C2;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x4F20;&#x5165;Builder&#xFF0C;Provider&#x7B49;</span>

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PizzaStore</span></span>{

    SimplePizzaFactory factory;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">PizzaStore</span><span class="hljs-params">(SimplePizzaFactory fac)</span></span>{
        <span class="hljs-keyword">this</span>.factory = fac;
    }


    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">orderPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
        pizza = factory.createPizza(type);
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
        <span class="hljs-keyword">return</span> pizza;
    }
}
<span class="hljs-comment">///</span>
</code></pre>
<h2 id="6-&#x5DE5;&#x5382;&#x65B9;&#x6CD5;">6 &#x5DE5;&#x5382;&#x65B9;&#x6CD5;</h2>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x4E0D;&#x662F;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x7684;&#x5347;&#x7EA7;&#xFF0C;<br>&#x800C;&#x662F;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x9700;&#x6C42;&#x5347;&#x7EA7;&#x4E86;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;&#x5347;&#x7EA7;&#x5C31;&#x662F;&#xFF0C;&#x51FA;&#x73B0;&#x4E86;&#x4E0D;&#x540C;&#x7684;&#x4EA7;&#x54C1;&#x7B49;&#x7EA7;<br>Pizza&#x5E97;&#x751F;&#x610F;&#x597D;&#x4E86;&#xFF0C;&#x91C7;&#x7528;&#x4E86;&#x52A0;&#x76DF;&#x6A21;&#x5F0F;&#xFF0C;NewYork, Chicago&#x90FD;&#x6709;&#x52A0;&#x76DF;&#x5E97;&#x4E86;&#xFF0C;<br>&#x4F46;&#x662F;&#x8FD9;&#x4E24;&#x4E2A;&#x5730;&#x65B9;&#x7684;Pizza&#x98CE;&#x5473;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x867D;&#x7136;&#x540C;&#x662F;Chesse&#x6216;&#x8005;Pepper&#xFF0C;&#x4F46;&#x662F;<br>&#x8FD8;&#x90FD;&#x6709;&#x5404;&#x81EA;&#x7684;&#x98CE;&#x5473;&#xFF0C;&#x5982;&#x997C;&#x7684;&#x539A;&#x8584;&#xFF0C;&#x997C;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x4F20;&#x5165;&#x540C;&#x6837;&#x7684;type&#xFF0C;&#x4F46;&#x8FD4;&#x56DE;&#x7684;&#x5BF9;&#x8C61;&#x4E0D;&#x4E00;&#x6837;&#x4E86;</p>
<blockquote>
<p>&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x5DE5;&#x5382;&#x63A5;&#x53E3;&#x6216;&#x57FA;&#x7C7B;&#xFF0C;&#x7531;&#x5B50;&#x7C7B;&#x5B8C;&#x6210;&#x5177;&#x4F53;&#x7684;&#x521B;&#x5EFA;&#x52A8;&#x4F5C;&#xFF0C;
&#x6240;&#x4EE5;&#x5DE5;&#x5382;&#x57FA;&#x7C7B;&#x4E2D;&#xFF0C;&#x5BF9;&#x5BF9;&#x8C61;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x5C31;&#x548C;&#x5B50;&#x7C7B;&#x7684;&#x521B;&#x5EFA;&#x52A8;&#x4F5C;&#x89E3;&#x8026;&#x4E86;</p>
</blockquote>
<p>&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#xFF0C;&#x80FD;&#x8BA9;&#x5404;&#x5730;&#x7684;Pizza&#x5E97;&#x8FD8;&#x4FDD;&#x6301;&#x4E00;&#x6837;&#x7684;&#x5236;&#x4F5C;&#x6D41;&#x7A0B;&#xFF0C;&#x4F46;&#x5404;&#x81EA;&#x5728;&#x521B;&#x5EFA;&#x65F6;&#xFF0C;&#x5141;&#x8BB8;&#x53D1;&#x6325;&#x4E2A;&#x6027;</p>
<pre><code class="lang-java">
<span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PizzaStore</span></span>{
        <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">orderPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
        pizza = createPizza(type);
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
        <span class="hljs-keyword">return</span> pizza;
    }
    <span class="hljs-function"><span class="hljs-keyword">abstract</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span></span>;
}
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NewYorkPizzaStore</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">PizzaStore</span></span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
        <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> NYCheesePizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;pepperoni&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> NYPepperoniPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;clam&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> NYClamPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggie&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> NYVeggiPizza();
        }
        <span class="hljs-keyword">return</span> pizza;
    }

}
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ChicogoPizzaStore</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">PizzaStore</span></span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
        <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGCheesePizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;pepperoni&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGPepperoniPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;clam&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGClamPizza();
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggie&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGVeggiPizza();
        }
        <span class="hljs-keyword">return</span> pizza;
    }

}
</code></pre>
<pre><code class="lang-java">Pizza&#x7684;&#x7C7B;&#x4F53;&#x7CFB;&#x8FD8;&#x662F;&#x5DEE;&#x4E0D;&#x591A;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NYCheesePizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NYPepperoniPizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CGCheesePizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CGPepperoniPizza</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Pizza</span></span>{

}
</code></pre>
<ul>
<li>&#x5206;&#x6790;<ul>
<li>&#x4E00;&#x6837;&#x7684;type&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x540C;&#x7684;&#x5DE5;&#x5382;&#x5B50;&#x7C7B;&#x8FD4;&#x56DE;&#x4E86;&#x4E0D;&#x540C;&#x7684;&#x7C7B;&#x578B;</li>
<li>&#x6BD4;&#x5982;&#x8BF4;&#x87BA;&#x4E1D;&#x5206;&#x4E3A;&#x5927;&#x5C0F;&#x87BA;&#x4E1D;&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x5927;&#x87BA;&#x4E1D;&#x5DE5;&#x5382;&#xFF0C;&#x5C0F;&#x87BA;&#x4E1D;&#x5DE5;&#x5382;&#xFF0C;&#x5927;&#x548C;&#x5C0F;&#x5C31;&#x662F;&#x4EA7;&#x54C1;&#x7B49;&#x7EA7;</li>
<li>&#x800C;&#x87BA;&#x4E1D;&#xFF0C;&#x87BA;&#x5E3D;&#x7CFB;&#x5217;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x65CF;&#xFF0C;&#x5BF9;&#x5E94;&#x5230;pizza&#x4E0A;&#xFF0C;&#x5C31;&#x662F;pizza&#xFF0C;&#x8FA3;&#x6912;&#xFF0C;&#x8C03;&#x6599;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x65CF;</li>
<li>&#x6D89;&#x53CA;&#x5230;&#x4EA7;&#x54C1;&#x65CF;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x7528;&#x5230;&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x4E86;</li>
</ul>
</li>
</ul>
<pre><code class="lang-java">&#x8FD9;&#x91CC;&#x7ED9;&#x51FA;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#xFF0C;&#x8FD8;&#x662F;&#x8981;&#x89E3;&#x51B3;&#x4E0A;&#x9762;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x4F46;&#x4E0D;&#x4F7F;&#x7528;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x7528;&#x66B4;&#x529B;&#x65B9;&#x6848;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DependentPizzaStore</span></span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String style, String type)</span></span>{
        Pizza pizza = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">if</span>(style.equals(<span class="hljs-string">&quot;NewYork&quot;</span>)){
            <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
                <span class="hljs-keyword">return</span> NYCheesePizza();
            }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggi&quot;</span>)){
                <span class="hljs-keyword">return</span> NYVeggiPizza();
            }
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(style.equals(<span class="hljs-string">&quot;Chicago&quot;</span>)){
            <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
                <span class="hljs-keyword">return</span> CGCheesePizza();
            }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggi&quot;</span>)){
                <span class="hljs-keyword">return</span> CGVeggiPizza();
            }
        }
        <span class="hljs-keyword">return</span> pizza;
    }

}

&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x5F88;&#x91CD;&#x8981;&#xFF0C;&#x5F88;&#x76F4;&#x89C2;&#x7684;&#x544A;&#x8BC9;&#x4F60;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x548C;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x89E3;&#x51B3;&#x7684;&#x95EE;&#x9898;

createPizza(String style, String type)&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF0C;style&#x5C31;&#x53D8;&#x6210;&#x4E86;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x91CC;&#x7684;&#x7C7B;&#x4F53;&#x7CFB;&#x7ED3;&#x6784;&#xFF0C;&#x6BCF;&#x4E2A;&#x5DE5;&#x5382;&#x5B50;&#x7C7B;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E0D;&#x540C;&#x7684;<span class="hljs-function">style

<span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span>&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;

&#x5982;&#x679C;&#x51FA;&#x73B0;&#x4E86;CreatePepper&#xFF0C; CreateSauce&#xFF0C;&#x9700;&#x8981;&#x4F60;&#x521B;&#x5EFA;&#x8FA3;&#x6912;&#x548C;&#x9171;&#x6599;&#xFF0C;&#x548C;Pizza&#x4E00;&#x8D77;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x65CF;&#xFF0C;&#x5C31;&#x7528;&#x5230;&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x4E86;
</span></code></pre>
<h2 id="7-&#x62BD;&#x8C61;&#x5DE5;&#x5382;">7 &#x62BD;&#x8C61;&#x5DE5;&#x5382;</h2>
<p>&#x770B;&#x5230;&#x8FD9;&#x91CC;&#x65F6;&#xFF0C;&#x4F60;&#x5E94;&#x8BE5;&#x5DF2;&#x7ECF;&#x4E86;&#x89E3;&#x4E86;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x548C;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</p>
<ul>
<li>&#x4F60;&#x5E94;&#x8BE5;&#x5DF2;&#x7ECF;&#x77E5;&#x9053;&#x4E86;<ul>
<li>&#x540C;&#x4E00;&#x4E2A;&#x4E1C;&#x897F;&#x7684;&#x4E0D;&#x540C;&#x98CE;&#x683C;&#xFF0C;&#x662F;&#x4EA7;&#x54C1;&#x7B49;&#x7EA7;&#x4E0D;&#x540C;&#xFF0C;&#x5982;&#x5927;&#x5C0F;&#x87BA;&#x4E1D;&#xFF0C;&#x9700;&#x8981;&#x4E0D;&#x540C;&#x98CE;&#x683C;&#x7684;&#x5DE5;&#x5382;--&#x5DE5;&#x5382;&#x65B9;&#x6CD5;</li>
<li>&#x4E0D;&#x540C;&#x7684;&#x4E1C;&#x897F;&#x5F62;&#x6210;&#x4E00;&#x4E2A;&#x7CFB;&#x5217;&#xFF0C;&#x5982;&#x87BA;&#x4E1D;&#x548C;&#x87BA;&#x5E3D;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x65CF;&#xFF0C;&#x5728;&#x4E00;&#x4E2A;&#x5DE5;&#x5382;&#x91CC;&#x751F;&#x4EA7;</li>
</ul>
</li>
</ul>
<pre><code class="lang-java">&#x73B0;&#x5728;&#x5047;&#x8BBE;&#x4E0D;&#x540C;&#x5730;&#x57DF;&#x7684;pizza&#x5E97;&#xFF0C;&#x5F97;&#x5C31;&#x8FD1;&#x751F;&#x4EA7;&#x81EA;&#x5DF1;&#x5730;&#x533A;&#x7684;&#x9171;&#x6599;&#x548C;&#x5976;&#x916A;&#xFF0C;&#x4EE5;&#x4FDD;&#x6301;&#x65B0;&#x9C9C;


<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">AbstractFactory</span></span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> Cheese <span class="hljs-title">createCheese</span><span class="hljs-params">()</span></span>;
    <span class="hljs-function"><span class="hljs-keyword">public</span> Sauce <span class="hljs-title">createSauce</span><span class="hljs-params">()</span></span>;
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NewYorkFactory</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractFactory</span></span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> Cheese <span class="hljs-title">createCheese</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> NYCheese();
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> Sauce <span class="hljs-title">createSauce</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> NYSauce();
    }
}
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CGFactory</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractFactory</span></span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> Cheese <span class="hljs-title">createCheese</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> CGCheese();
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> Sauce <span class="hljs-title">createSauce</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> CGSauce();
    }
}


&#x8FD9;&#x4FE9;&#x5DE5;&#x5382;&#x7528;&#x5728;&#x54EA;&#x513F;&#x5462;&#xFF1F;&#x6CE8;&#x610F;&#xFF0C;&#x9171;&#x6599;&#x548C;&#x5976;&#x916A;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x65CF;&#xFF0C;&#x4ED6;&#x4EEC;&#x7EC4;&#x88C5;&#x51FA;&#x6765;&#x7684;&#x4EA7;&#x54C1;&#x5C31;&#x662F;&#xFF1A;Pizza

&#x6240;&#x4EE5;&#x8FD9;&#x91CC;&#x7684;&#x5DE5;&#x5382;&#xFF0C;&#x5E94;&#x8BE5;&#x7528;&#x5728;&#x7EC4;&#x88C5;Pizza&#x7684;&#x5730;&#x65B9;
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ChicogoPizzaFactory</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">PizzaFactory</span></span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Pizza <span class="hljs-title">createPizza</span><span class="hljs-params">(String type)</span></span>{
        Pizza pizza;
                AbstractFactory fac = <span class="hljs-keyword">new</span> CGFactory();
        <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;cheese&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGCheesePizza(fac);
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;pepperoni&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGPepperoniPizza(fac);
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;clam&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGClamPizza(fac);
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(type.equals(<span class="hljs-string">&quot;veggie&quot;</span>)){
            pizza = <span class="hljs-keyword">new</span> CGVeggiPizza(fac);
        }
        <span class="hljs-keyword">return</span> pizza;
    }

}
</code></pre>
<ul>
<li>&#x4E09;&#x4E2A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x7684;&#x603B;&#x7ED3;&#xFF1A;<ul>
<li>&#x7B80;&#x5355;&#x5DE5;&#x5382;&#xFF1A;&#x89E3;&#x51B3;&#x4E86;&#x5355;&#x4E2A;&#x5E97;&#x9762;&#x7684;&#x9009;&#x62E9;&#x4E0D;&#x540C;&#x7C7B;&#x578B;pizza&#x7684;&#x95EE;&#x9898;</li>
<li>&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#xFF1A;&#x89E3;&#x51B3;&#x4E86;&#x4E0D;&#x540C;&#x5730;&#x57DF;Pizza&#x5E97;&#x7684;&#x53E3;&#x5473;&#x95EE;&#x9898;&#xFF0C;&#x540C;&#x4E00;&#x7C7B;&#x578B;&#x7684;pizza&#x53EF;&#x4EE5;&#x505A;&#x51FA;&#x4E0D;&#x540C;&#x98CE;&#x683C;</li>
<li>&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#xFF1A;&#x89E3;&#x51B3;&#x4E86;&#x4E0D;&#x540C;&#x5730;&#x57DF;&#x7684;Pizza&#x539F;&#x6599;&#x751F;&#x4EA7;&#x95EE;&#x9898;&#xFF0C;&#x539F;&#x6599;&#x4F5C;&#x4E3A;&#x4EA7;&#x54C1;&#x65CF;</li>
<li>&#x8FD9;&#x91CC;Pizza&#x7684;&#x4F8B;&#x5B50;&#x6269;&#x5C55;&#x5230;&#x5973;&#x5A32;&#x9020;&#x4EBA;&#x7684;&#x573A;&#x666F;&#x91CC;<ul>
<li>&#x4EBA;&#x7684;&#x7C7B;&#x578B;&#xFF1A;&#x7537;&#x4EBA;&#xFF0C;&#x5973;&#x4EBA;---&#x7531;&#x7B80;&#x5355;&#x5DE5;&#x5382;&#x89E3;&#x51B3;&#xFF0C;SimpleFactory.createHuman(type)</li>
<li>&#x4EBA;&#x7684;&#x4E0D;&#x540C;&#x98CE;&#x683C;&#xFF1A;&#x9EC4;&#x8272;&#xFF0C;&#x9ED1;&#x8272;&#xFF0C;&#x767D;&#x8272;--&#x7531;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x89E3;&#x51B3;<ul>
<li>IHumanFactory.createHuman(type)</li>
<li>&#x5206;&#x4E3A;YellowFactory&#xFF0C;BlackFactory&#xFF0C;WhiteFactory</li>
</ul>
</li>
<li>&#x4EBA;&#x7684;&#x96F6;&#x4EF6;&#x95EE;&#x9898;&#xFF1A;&#x80F3;&#x818A;&#xFF0C;&#x817F;&#xFF0C;&#x8111;&#x888B;<ul>
<li>AbstractFactory.create&#x80F3;&#x818A;&#xFF0C;create&#x817F;&#xFF0C;create&#x8111;&#x888B;</li>
<li>Yellow&#x96F6;&#x4EF6;Factory&#xFF0C;Black&#x96F6;&#x4EF6;Factory&#xFF0C;White&#x96F6;&#x4EF6;Factory</li>
<li>&#x800C;&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#xFF0C;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x7ED9;&#x4E0A;&#x9762;&#x4E0D;&#x540C;&#x80A4;&#x8272;&#x7684;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x4F7F;&#x7528;&#xFF0C;&#x6765;&#x7EC4;&#x88C5;&#x6210;&#x4E0D;&#x540C;&#x80A4;&#x8272;&#x7684;&#x4EBA;</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="8-flyweight&#xFF1A;&#x8747;&#x91CF;&#x6A21;&#x5F0F;&#xFF08;&#x4EAB;&#x5143;&#x6A21;&#x5F0F;&#xFF09;">8 Flyweight&#xFF1A;&#x8747;&#x91CF;&#x6A21;&#x5F0F;&#xFF08;&#x4EAB;&#x5143;&#x6A21;&#x5F0F;&#xFF09;</h2>
<ul>
<li>&#x573A;&#x666F;&#xFF1A;<ul>
<li>&#x4E00;&#x4E2A;&#x68EE;&#x6797;&#x91CC;&#x6709;&#x5F88;&#x591A;&#x6811;&#xFF0C;&#x6811;&#x6709;&#x5343;&#x4E07;&#x68F5;&#xFF0C;&#x4F46;&#x4E00;&#x5171;&#x5C31;&#x4E09;&#x79CD;&#xFF08;&#x67F3;&#x6811;&#xFF0C;&#x69D0;&#x6811;&#xFF0C;&#x6768;&#x6811;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x5C31;&#x662F;&#x6811;&#x7684;&#x4F4D;&#x7F6E;&#x4E0D;&#x540C;&#xFF0C;&#x6811;&#x7684;&#x6837;&#x5B50;&#x662F;&#x5916;&#x90E8;&#x72B6;&#x6001;&#xFF0C;&#x6811;&#x7684;&#x4F4D;&#x7F6E;&#x662F;&#x5185;&#x90E8;&#x72B6;&#x6001;</li>
<li>&#x4E00;&#x4E2A;&#x5E74;&#x7EA7;&#x5F88;&#x591A;Student&#xFF0C;&#x5404;&#x4E2A;Student&#x4FDD;&#x5B58;&#x4E00;&#x4E2A;Class&#x73ED;&#x7EA7;&#x4FE1;&#x606F;&#xFF0C;&#x5176;&#x5B9E;1000&#x4E2A;&#x5B66;&#x751F;&#xFF0C;&#x5C31;10&#x4E2A;Class&#xFF0C;Class&#x662F;&#x5916;&#x90E8;&#x72B6;&#x6001;&#xFF0C;&#x5176;&#x4ED6;&#x5982;&#x59D3;&#x540D;&#xFF0C;&#x751F;&#x65E5;&#xFF0C;&#x6210;&#x7EE9;&#xFF0C;&#x662F;&#x5185;&#x90E8;&#x72B6;&#x6001;</li>
<li>&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x5F88;&#x591A;&#x5B57;&#x6BB5;&#xFF0C;&#x4F46;&#x6709;&#x4E00;&#x7EC4;&#x5B57;&#x6BB5;&#x662F;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x90FD;&#x4E00;&#x6837;&#x7684;&#xFF0C;1000&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x80FD;&#x8FD9;&#x4E00;&#x7EC4;&#x5B57;&#x6BB5;&#x5C31;&#x51E0;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x8FD9;&#x4E00;&#x7EC4;&#x5B57;&#x6BB5;&#xFF0C;&#x5C31;&#x662F;&#x5916;&#x90E8;&#x72B6;&#x6001;&#xFF0C;&#x5176;&#x4ED6;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x662F;&#x5185;&#x90E8;&#x72B6;&#x6001;</li>
</ul>
</li>
</ul>
<blockquote>
<p>Flyweight&#x6A21;&#x5F0F;&#x5C31;&#x662F;&#x89E3;&#x51B3;&#x5916;&#x90E8;&#x72B6;&#x6001;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x7528;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x63D0;&#x4F9B;&#x5F88;&#x591A;&#x4E2A;&#x865A;&#x62DF;&#x5BF9;&#x8C61;</p>
</blockquote>
<pre><code class="lang-java">
<span class="hljs-comment">//&#x6811;&#x7684;&#x5BF9;&#x8C61;&#x5343;&#x5343;&#x4E07;&#xFF0C;&#x4F46;&#x4E0D;&#x6015;&#xFF0C;&#x8FD9;&#x91CC;&#x8D70;&#x4E86;&#x4E2A;&#x6781;&#x7AEF;&#xFF0C;&#x6811;&#x6210;&#x4E86;&#x65E0;&#x72B6;&#x6001;&#x5BF9;&#x8C61;&#xFF0C;&#x5176;&#x5B9E;&#x53EF;&#x4EE5;&#x6709;&#x5185;&#x90E8;&#x72B6;&#x6001;&#xFF0C;</span>
<span class="hljs-comment">//&#x5982;&#x4F4D;&#x7F6E;xy&#x548C;&#x6811;&#x9F84;age&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x4F7F;&#x7528;&#xFF0C;&#x800C;&#x975E;&#x65B9;&#x6CD5;&#x53C2;&#x6570;</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Tree</span></span>{
    RealTree realTree;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y, <span class="hljs-keyword">int</span> age)</span></span>{

    }
}

<span class="hljs-comment">///&#x6811;&#x7684;&#x5916;&#x90E8;&#x72B6;&#x6001;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x4E09;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x67F3;&#x6811;&#xFF0C;&#x6768;&#x6811;&#xFF0C;&#x69D0;&#x6811;</span>
<span class="hljs-comment">//&#x8FD9;&#x91CC;&#x8FD9;&#x51E0;&#x4E2A;&#x5B57;&#x6BB5;&#x8BF4;&#x662F;&#x56FA;&#x5B9A;&#x4E0D;&#x53D8;&#x7684;&#xFF0C;&#x53EF;&#x80FD;&#x6709;&#x70B9;&#x7275;&#x5F3A;&#xFF0C;&#x4E0D;&#x8981;&#x592A;&#x7EA0;&#x7ED3;</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RealTree</span></span>{
    <span class="hljs-keyword">public</span> Leaf leaf;
    <span class="hljs-keyword">public</span> Type type;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> &#x786C;&#x5EA6;;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> &#x679C;&#x5B9E;;
}


<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TreeManager</span></span>{
    <span class="hljs-keyword">public</span> HashMap&lt;String, RealTree&gt; flyweights = ...;
    <span class="hljs-keyword">static</span>{
      flyweights.put(<span class="hljs-string">&quot;&#x6768;&#x6811;&quot;</span>, <span class="hljs-keyword">new</span> RealTree());
      ....
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> RealTree <span class="hljs-title">getRealTree</span><span class="hljs-params">(String key)</span></span>{...}

}
</code></pre>
<h2 id="9-&#x5907;&#x5FD8;&#x5F55;&#x6A21;&#x5F0F;">9 &#x5907;&#x5FD8;&#x5F55;&#x6A21;&#x5F0F;</h2>
<p>&#x5BF9;&#x8C61;&#x5FEB;&#x7167;&#xFF0C;&#x4F8B;&#x5982;&#x5728;&#x547D;&#x4EE4;&#x6A21;&#x5F0F;&#x7684;&#x64A4;&#x9500;&#x529F;&#x80FD;&#x4E2D;&#xFF0C;&#x9700;&#x8981;&#x8BB0;&#x4F4F;&#x5BF9;&#x8C61;&#x4E4B;&#x524D;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x6216;&#x8005;&#x6E38;&#x620F;&#x7684;&#x8FDB;&#x5EA6;&#x4FDD;&#x5B58;  </p>
<p>&#x5907;&#x5FD8;&#x5F55;&#x6A21;&#x5F0F;&#x5C31;&#x662F;&#x7531;&#x5BF9;&#x8C61;&#x81EA;&#x5DF1;&#x7BA1;&#x7406;&#x81EA;&#x5DF1;&#x7684;save&#x548C;restore</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GameRole</span></span>{

    <span class="hljs-keyword">private</span> String currentEnemy;
    <span class="hljs-keyword">private</span> String currentFriend;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> currentX, currentY;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> currentAttachPower;

    <span class="hljs-function"><span class="hljs-keyword">public</span> Memento <span class="hljs-title">createMemento</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Memento(currentX, currentY);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setMemento</span><span class="hljs-params">(Memento memento)</span></span>{
        <span class="hljs-keyword">this</span>.currentX = memento.currentX;
        <span class="hljs-keyword">this</span>.currentY = memento.currentY;
    }
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Memento</span></span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> currentX, currentY; <span class="hljs-comment">//&#x5F53;&#x524D;&#x4F4D;&#x7F6E;&#x5750;&#x6807;&#xFF0C;&#x9700;&#x8981;&#x4FDD;&#x5B58;&#x548C;&#x8FD8;&#x539F;</span>
}
</code></pre>
<h2 id="10-&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x548C;&#x6DF1;&#x62F7;&#x8D1D;&#x6D45;&#x62F7;&#x8D1D;">10 &#x539F;&#x578B;&#x6A21;&#x5F0F;&#x548C;&#x6DF1;&#x62F7;&#x8D1D;&#x6D45;&#x62F7;&#x8D1D;</h2>
<p>&#x6DF1;&#x62F7;&#x8D1D;&#x4E0E;&#x6D45;&#x62F7;&#x8D1D;&#x95EE;&#x9898;&#x4E2D;&#xFF0C;&#x4F1A;&#x53D1;&#x751F;&#x6DF1;&#x62F7;&#x8D1D;&#x7684;&#x6709;java&#x4E2D;&#x7684;8&#x79CD;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x4EE5;&#x53CA;&#x4ED6;&#x4EEC;&#x7684;&#x88C5;&#x7BB1;&#x7C7B;&#x578B;&#xFF0C;&#x53E6;&#x5916;&#x8FD8;&#x6709;String&#x7C7B;&#x578B;&#x3002;&#x5176;&#x4F59;&#x7684;&#x90FD;&#x662F;&#x6D45;&#x62F7;&#x8D1D;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Prototype</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Cloneable</span> </span>{  
    <span class="hljs-keyword">private</span> ArrayList list = <span class="hljs-keyword">new</span> ArrayList();  
    <span class="hljs-function"><span class="hljs-keyword">public</span> Prototype <span class="hljs-title">clone</span><span class="hljs-params">()</span></span>{  
        Prototype prototype = <span class="hljs-keyword">null</span>;  
        <span class="hljs-keyword">try</span>{  
            prototype = (Prototype)<span class="hljs-keyword">super</span>.clone();  
            prototype.list = (ArrayList) <span class="hljs-keyword">this</span>.list.clone();  
        }<span class="hljs-keyword">catch</span>(CloneNotSupportedException e){  
            e.printStackTrace();  
        }  
        <span class="hljs-keyword">return</span> prototype;   
    }  
}
</code></pre>
<ul>
<li>&#x4F60;&#x9700;&#x8981;&#x5F04;&#x6E05;&#x695A;&#x7684;&#x95EE;&#x9898;&#xFF1A;<ul>
<li>&#x4F60;&#x7684;&#x5BF9;&#x8C61;&#x5230;&#x5E95;&#x8981;&#x5BF9;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x57DF;&#x62F7;&#x8D1D;&#x5230;&#x4EC0;&#x4E48;&#x7A0B;&#x5EA6;</li>
<li>&#x57DF;&#x7684;&#x7C7B;&#x578B;&#x662F;&#x5426;&#x5B9E;&#x73B0;&#x4E86;clone&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x4F60;&#x5B9E;&#x73B0;&#x8FD8;&#x662F;JDK&#x5B9E;&#x73B0;&#xFF0C;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x4F60;&#x5F97;&#x77E5;&#x9053;</li>
<li>&#x5C31;&#x4E0A;&#x4F8B;&#x800C;&#x8A00;&#xFF1A;&#x7531;&#x4E8E;ArrayList&#x4E0D;&#x662F;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#xFF0C;&#x6240;&#x4EE5;&#x6210;&#x5458;&#x53D8;&#x91CF;list&#xFF0C;&#x4E0D;&#x4F1A;&#x88AB;&#x62F7;&#x8D1D;&#xFF0C;&#x9700;&#x8981;&#x6211;&#x4EEC;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x6DF1;&#x62F7;&#x8D1D;&#xFF0C;&#x5E78;&#x8FD0;&#x7684;&#x662F;java&#x63D0;&#x4F9B;&#x7684;&#x5927;&#x90E8;&#x5206;&#x7684;&#x5BB9;&#x5668;&#x7C7B;&#x90FD;&#x5B9E;&#x73B0;&#x4E86;Cloneable&#x63A5;&#x53E3;&#x3002;&#x6240;&#x4EE5;&#x5B9E;&#x73B0;&#x6DF1;&#x62F7;&#x8D1D;&#x5E76;&#x4E0D;&#x662F;&#x7279;&#x522B;&#x56F0;&#x96BE;&#x3002;</li>
</ul>
</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Introduction">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="enum.html" class="navigation navigation-next " aria-label="Next page: 枚举">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"对象管理","level":"1.2","depth":1,"next":{"title":"枚举","level":"1.3","depth":1,"path":"enum.md","ref":"enum.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"object-mgmr.md","mtime":"2017-04-09T05:58:16.713Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-09T09:50:22.406Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

